#include <malloc.h>
#include <stdlib.h>

#include "lib.h"
#include "alpbitmap.h"
#include "bitmap.h"
#include "screen.h"
#include "frame.h"

static pCAlphaCache g_alphaCache = 0;

pCAlphaBitmap
newCAlphaBitmap(char * BitmapName, char* AlphaChannel, uint32 Group)
{
	pCAlphaBitmap This = NULL;

	This = (pCAlphaBitmap)malloc(sizeof(CAlphaBitmap));
	
	if (This)
	{
		This->bitmap = newCBitmap(BitmapName, Group);
		This->alpchannel = newCBitmap(AlphaChannel, Group);

		if (!This->bitmap)
		{
			deleteCAlphaBitmap(This);
			This = 0;
		}
		else if (This->alpchannel && 
			(CBitmapWidth(This->bitmap) != CBitmapWidth(This->alpchannel) ||
			CBitmapHeight(This->bitmap) != CBitmapHeight(This->alpchannel)))
		{
			DEBUGMSG(("newCAlphaBitmap(): %s differ is size.", BitmapName, AlphaChannel));

			deleteCAlphaBitmap(This);
			This = 0;
		}
	}

	return This;
}

void		
deleteCAlphaBitmap(pCAlphaBitmap This)
{
	if (This)
	{
		deleteCBitmap(This->bitmap);
		This->bitmap = 0;

		deleteCBitmap(This->alpchannel);
		This->alpchannel = 0;

		CAlphaBitmapDestruct(This);
		free(This);
	}
}

void
CAlphaBitmapDestruct(pCAlphaBitmap This)
{	
	//do nothing
}


pCAlphaBitmap
newCAlphaBitmapBlank(int32 width, int32 height)
{
	pCAlphaBitmap This = NULL;

	This = (pCAlphaBitmap)malloc(sizeof(CAlphaBitmap));
	
	if (This)
	{
		This->bitmap = newCBitmapBlank(width, height);
		This->alpchannel = newCBitmapBlank(width, height);
	}

	return This;
}
